From: Carlos Garnacho Date: Tue, 11 Oct 2022 16:23:19 +0000 (+0200) Subject: keyboard: Refactor code X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~435^2^2~18 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=766314acb2a3305fb692f3ef1e5948b1f60c5f00;p=gnome-shell.git keyboard: Refactor code Move inline anonymous function to be its own. This method will become asynchronous in following commits. Part-of: --- diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js index 895691c34..28369316e 100644 --- a/js/ui/keyboard.js +++ b/js/ui/keyboard.js @@ -1510,31 +1510,8 @@ var Keyboard = GObject.registerClass({ button.setWidth(key.width); if (key.action !== 'modifier') { - button.connect('commit', (actor, keyval, str) => { - if (this._modifiers.size === 0 && str !== '' && - keyval && this._oskCompletionEnabled) { - Main.inputMethod.handleVirtualKey(keyval); - return; - } - - if (str === '' || !Main.inputMethod.currentFocus || - (keyval && this._oskCompletionEnabled) || - this._modifiers.size > 0 || - !this._keyboardController.commitString(str, true)) { - if (keyval !== 0) { - this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_PRESS); - this._keyboardController.keyvalPress(keyval); - GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => { - this._keyboardController.keyvalRelease(keyval); - this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_RELEASE); - this._disableAllModifiers(); - return GLib.SOURCE_REMOVE; - }); - } - } - - if (!this._latched) - this._setActiveLayer(0); + button.connect('commit', (_actor, keyval, str) => { + this._commitAction(keyval, str); }); } @@ -1592,6 +1569,33 @@ var Keyboard = GObject.registerClass({ } } + _commitAction(keyval, str) { + if (this._modifiers.size === 0 && str !== '' && + keyval && this._oskCompletionEnabled) { + Main.inputMethod.handleVirtualKey(keyval); + return; + } + + if (str === '' || !Main.inputMethod.currentFocus || + (keyval && this._oskCompletionEnabled) || + this._modifiers.size > 0 || + !this._keyboardController.commitString(str, true)) { + if (keyval !== 0) { + this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_PRESS); + this._keyboardController.keyvalPress(keyval); + GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => { + this._keyboardController.keyvalRelease(keyval); + this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_RELEASE); + this._disableAllModifiers(); + return GLib.SOURCE_REMOVE; + }); + } + } + + if (!this._latched) + this._setActiveLayer(0); + } + _previousWordPosition(text, cursor) { /* Skip word prior to cursor */ let pos = Math.max(0, text.slice(0, cursor).search(/\s+\S+\s*$/));